#! /bin/sh
#
# usage: ./configure.sh -apache PATH-TO-APACHE2

USAGE="usage: configure.sh -apache PATH-TO-APACHE"

if [ "$1x" = x ]
then
  echo $USAGE
  exit 1
elif [ $1 != '-apache' ]
then
  echo $USAGE
  exit 1
elif [ "$2x" = x ]
then
  echo $USAGE
  exit 1
fi

APACHE=$2

if [ ! -f "$APACHE/build/special.mk" ]
then
  echo "'$APACHE' doesn't seem to be an Apache 2 installation"
  exit 1
fi

if [ ! -f tidy/include/buffio.h ]
then
  echo "Fetching and building TidyLib"
  cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co -P tidy
  (cd tidy && sh build/gnuauto/setup.sh)
  (cd tidy && ./configure)
  (cd tidy && make)
fi

echo "Writing Makefile"
cat > Makefile <<EoF
# originally from apxs -g

builddir=.
top_srcdir=$APACHE
top_builddir=$APACHE
include $APACHE/build/special.mk

EXTRA_CFLAGS = -g -Wall -Itidy/include

#   the used tools
APXS=apxs
APACHECTL=apachectl

#   the default target
all: local-shared-build

#   install the shared object file into Apache 
install: install-modules-yes

#   cleanup
clean:
	-rm -f *.o *.lo *.slo *.la 
EoF



